package com.kaifamiao.date1103;

public class Snake {
	
	public long sum( long n ) {
		if( n == 1 ) {
			return 1 ;
		}
		return n + sum( n - 1);
	}
	
	public long factorial( long n ) {
		if( n < 0 ) {
			throw new RuntimeException( "你龟儿子数学咋个学的？负数是没得阶乘的" );
		}
		if( n == 0 || n== 1 ) {
			return 1 ; // 数学中规定 0 和 1 的阶乘都是 1 
		}
		return n * factorial( n - 1 );
	}
	
	public static void main(String[] args) {
		Snake s = new Snake();
		
		long m = s.sum( 100 );
		System.out.println( m );
		
		long f = s.factorial( 5 );
		System.out.println( f );
		
	}

}
